<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script type="text/javascript">
var timer_id;
var show_log_id ;
function readLog(){
    Page.postJSON({
        json: {cmd:145,tool:"get_log"},
        success: function(data) {
           // AlertUtil.alertMsg(data["data"]);
            show_log_id.text(data["data"]);
        }
    });
}

function readSize(){
    Page.postJSON({
        json: {cmd:145,tool:"get_size"},
        success: function(data) {
           // AlertUtil.alertMsg(data["data"]);
            show_log_id.text(data["data"] + "B");
        }
    });
}

    $(document).ready(function(){
        var fm1 = ["form1", "form1Parent", "form1Id"];
        var fm2 = ["form2", "form2Parent", "form2Id"];
        var fm3 = ["form3", "form3Parent", "form3Id"];
        var fm4 = ["form4", "form4Parent", "form4Id"];
        var fm5 = ["form5", "form5Parent", "form5Id"];
        Page.createForm(fm1);
        Page.createForm(fm2);
        Page.createForm(fm3);
        Page.createForm(fm4);
        Page.createForm(fm5);
        TempUtil.render('tabsitems-template', 'tabsitems', networktoolhtml.tab_menu);
        TempUtil.render('networktoolform1-template', 'form1', networktoolhtml.form1);
        TempUtil.render('networktoolform2-template', 'form2', networktoolhtml.form2);
        TempUtil.render('networktoolform3-template', 'form3', networktoolhtml.form3);
        TempUtil.render('networktoolform4-template', 'form4', networktoolhtml.form4);
        TempUtil.render('networktoolform5-template', 'form5', networktoolhtml.form5);
        var showText = networktoolhtml.prompt;

        var $lis = $("ul.tabs a");
        var $boxes = $("div.tab_boxes > div");
        var $btnSaveLan = $('#btnSaveLan');



        $('#btnPingStart');
        $('#btnPingStop').attr("disabled",true);
        $('#btnCatchPkgStart');
        $('#btnCatchPkgStop').attr("disabled",true);
        $('#btnTraceStart');
        $('#btnTraceStop').attr("disabled",true);
        $('#btnLogStart');
        $('#btnLogStop').attr("disabled",true);
        $('#catchPkglink').hide();
        $('#logLink').hide()
        $lis.click(function() {
            $lis.removeClass("current");
            $(this).addClass("current");
            var pannelIndex = $lis.index(this);
            $boxes.eq(pannelIndex).show().siblings().hide();
        });

        $lis.eq(0).click();


        //PING
        $('#btnPingStart').click(function(){
            $(this).attr("disabled",true);
            $('#btnPingStop').attr("disabled",false);
            var count = 0;
            var $form = $('#form1');
        // AlertUtil.alertMsg("click ping start");
            var json = JSON.parmsToJSON($form);

            json.method = JSONMethod.POST;
            json.cmd = RequestCmd.NETWORK_TOOL;
            json.tool = 'ping_start'
            Page.postJSON({
                json: json,
                success: function(data) {
                   // AlertUtil.alertMsg(data);
                }
            });

            timer_id = window.setInterval("readLog()", 2000); 
            show_log_id = $('#PingTxtPingResult')
        });

         $('#btnPingStop').click(function(){
            $(this).attr("disabled",true);
            $('#btnPingStart').attr("disabled",false);
            var count = 0;
            var $form = $('#form1');
         
            var json = JSON.parmsToJSON($form);
        //AlertUtil.alertMsg("click ping stop");
            json.method = JSONMethod.POST;
            json.cmd = RequestCmd.NETWORK_TOOL;
            json.tool = 'ping_stop'
            Page.postJSON({
                json: json,
                success: function(data) {
                    //AlertUtil.alertMsg(data);
                }
            });

             window.clearInterval(timer_id);
        });

        //Catch pkg
        $('#btnCatchPkgStart').click(function(){
            $(this).attr("disabled",true);
            $('#btnCatchPkgStop').attr("disabled",false);
            var count = 0;
            var $form = $('#form2');
        // AlertUtil.alertMsg("click ping start");
            var json = JSON.parmsToJSON($form);

            json.method = JSONMethod.POST;
            json.cmd = RequestCmd.NETWORK_TOOL;
            json.tool = 'catch_pkg_start'
            Page.postJSON({
                json: json,
                success: function(data) {
                    $('#catchPkglink').hide();
                    if (data["data"] == "NOTCPDUMP")
                    {
                        AlertUtil.alertMsg(networktoolhtml.form2.tipLabel);
                        $('#btnCatchPkgStart').attr("disabled",false);
                        $('#btnCatchPkgStop').attr("disabled",true);
                        return ;
                    }
                    timer_id = window.setInterval("readSize()", 2000); 
                    show_log_id = $('#catchPkgLable')
                    
                }
            });

          
        });

        $('#btnCatchPkgStop').click(function(){
            $(this).attr("disabled",true);
            $('#btnCatchPkgStart').attr("disabled",false);
            var count = 0;
            var $form = $('#form2');
         
            var json = JSON.parmsToJSON($form);
        //AlertUtil.alertMsg("click ping stop");
            json.method = JSONMethod.POST;
            json.cmd = RequestCmd.NETWORK_TOOL;
            json.tool = 'catch_pkg_stop'
            Page.postJSON({
                json: json,
                success: function(data) {
                    $('#catchPkglink').show();
                }
            });

             window.clearInterval(timer_id);
        });


        //TraceRoute
        $('#btnTraceStart').click(function(){
            $(this).attr("disabled",true);
            $('#btnTraceStop').attr("disabled",false);
            var count = 0;
            var $form = $('#form3');
        // AlertUtil.alertMsg("click ping start");
            var json = JSON.parmsToJSON($form);

            json.method = JSONMethod.POST;
            json.cmd = RequestCmd.NETWORK_TOOL;
            json.tool = 'trace_start'
            Page.postJSON({
                json: json,
                success: function(data) {
                }
            });

            timer_id = window.setInterval("readLog()", 2000); 
            show_log_id = $('#traceTxtResult')
        });

         $('#btnTraceStop').click(function(){
            $(this).attr("disabled",true);
            $('#btnTraceStart').attr("disabled",false);
            var count = 0;
            var $form = $('#form3');
         
            var json = JSON.parmsToJSON($form);
        //AlertUtil.alertMsg("click ping stop");
            json.method = JSONMethod.POST;
            json.cmd = RequestCmd.NETWORK_TOOL;
            json.tool = 'trace_stop'
            Page.postJSON({
                json: json,
                success: function(data) {
                }
            });

             window.clearInterval(timer_id);
        });

          //System Log 
        $('#btnLogStart').click(function(){
            $(this).attr("disabled",true);
            $('#btnLogStop').attr("disabled",false);
            var count = 0;
            var $form = $('#form4');
        // AlertUtil.alertMsg("click ping start");
            var json = JSON.parmsToJSON($form);

            json.method = JSONMethod.POST;
            json.cmd = RequestCmd.NETWORK_TOOL;
            json.tool = 'log_start'
            Page.postJSON({
                json: json,
                success: function(data) {
                    $('#logLink').hide();
                }
            });

            timer_id = window.setInterval("readSize()", 2000); 
            show_log_id = $('#logLable')
        });

        $('#btnLogStop').click(function(){
            $(this).attr("disabled",true);
            $('#btnLogStart').attr("disabled",false);
            var count = 0;
            var $form = $('#form4');
         
            var json = JSON.parmsToJSON($form);
        //AlertUtil.alertMsg("click ping stop");
            json.method = JSONMethod.POST;
            json.cmd = RequestCmd.NETWORK_TOOL;
            json.tool = 'log_stop'
            Page.postJSON({
                json: json,
                success: function(data) {
                    $('#logLink').show();
                }
            });

             window.clearInterval(timer_id);
        });


        //qxdm log switch

        var $form5 = $('#form5');
        var json = JSON.parmsToJSON($form5);
        json.method = JSONMethod.POST;
        json.cmd = RequestCmd.SOCKETAT_GET;
        Page.postJSON({
            json: json,
            success: function(data) {
                $('#qxdmSwitch').attr("checked",data.swtich);
            }
        });

        $('#btnSetting').click(function(){
            var $form5 = $('#form5');
            var json = JSON.parmsToJSON($form5);
            json.method = JSONMethod.POST;
            json.cmd = RequestCmd.SOCKETAT_SET;

            var status = $('#qxdmSwitch').is(":checked");
            json.appEnable = status;
            Page.postJSON({
                json: json,
                success: function(data) {
                    AlertUtil.alertMsg(PROMPT.saving.success);
                }
            });
        });

    });
</script>

<div class="detail_box">
    <div class="tab_menu">
        <ul class="tabs" id="tabsitems">
            <script type="text/template" id="tabsitems-template">
                <li><a href="javascript:;"><%- item1 %></a></li>
                <li><a href="javascript:;"><%- item2 %></a></li>
                <li><a href="javascript:;"><%- item3 %></a></li>
                <li><a href="javascript:;"><%- item4 %></a></li>
                <li><a href="javascript:;"><%- item5 %></a></li>
            </script>
        </ul>
    </div>
    <div class="tab_menu_bottom"></div>
    <div>
        <div class="tab_boxes">
            <div class="main_box" id="form1Parent">
                <div id="form1Id">
                     <!-- <form id="form1"> -->
                        <script type="text/template" id="networktoolform1-template">
                            <table class="detail" cellspacing="0"><tr>
                                <th><%- th1 %>&nbsp;</th>
                                <td><input type="text" id="pingNum" name="pingNum" class="normal inputs_lan"  />
                                <input type="checkbox" name="pingLoop" value="1"><%- th1radio%></td>
                                </tr>
    
                                <tr class="odd">
                                    <th><%- th2 %>&nbsp;</th>
                                    <td><input type="text" id="pingUrl" name="pingUrl" class="normal inputs_lan"/></td></tr>
    
                                
                                <tr id="trSaveLan" class="even" >
                                    <th>&nbsp;</th>
                                    <td>
                                        <input type="button" id="btnPingStart" value="<%- btnStart %>"/>
                                        <input type="button" id="btnPingStop" value="<%- btnStop %>"/>
                                    </td>
                                </tr>
    
                                <tr class="odd">
                                    <th>&nbsp;</th>
                                    <td>
                                        <textarea id="PingTxtPingResult" cols="80" rows="20"></textarea>
                                        <br>
                                        <input type="button" onclick="javascript:$('#PingTxtPingResult').text('')" value="<%- btnClear %>">
                                    </td>
                                </tr>
                            </table>
                        </script>
                    <!-- </form> -->
                </div>          
            </div>

            <div class="main_box" id="form2Parent">
                <div id="form2Id">
                      <!-- <form id="form2"> -->
                        <script type="text/template" id="networktoolform2-template">
                            <table class="detail" cellspacing="0">
                                <tr><td colspan="2"><span class="cmt"><%- tipLabel %></span></td></tr>
                                <tr>
                                <th><%- th1 %>&nbsp;</th>
                                <td><input type="text" id="catchPackageIfname" name="catchPackageIfname" class="normal inputs_lan"  />
                                    <span class="cmt"><%- th1tip %></span>
                                </td>
                                </tr>
    
                                <tr id="trSaveLan" class="even" >
                                    <th>&nbsp;</th>
                                    <td>
                                        <input type="button" id="btnCatchPkgStart" value="<%- btnStart %>"/>
                                        <input type="button" id="btnCatchPkgStop" value="<%- btnStop %>"/>
                                    </td>
                                </tr>
    
                                <tr class="odd">
                                    <th><%- th2 %>&nbsp;</th>
                                    <td>
                                        <label id="catchPkgLable"></label>
                                        <a id="catchPkglink" href="html/manage/network_tool_log.tcpdump" download><%- downfile %></a>
                                    </td>
                                </tr>
                            </table>
                        </script>
                    <!-- </form> -->
                </div>            
            </div>

            <div class="main_box" id="form3Parent">
                <div id="form3Id">
                     <!-- <form id="form3"> -->
                        <script type="text/template" id="networktoolform3-template">
                            <table class="detail" cellspacing="0">
                                <tr class="odd">
                                    <th><%- th1 %>&nbsp;</th>
                                    <td><input type="text" id="traceUrl" name="traceUrl" class="normal inputs_lan"/></td>
                                </tr>
                                    <tr class="odd">
                                    <th><%- th2 %>&nbsp;</th>
                                    <td><input type="text" id="tracePort" name="tracePort" class="normal inputs_lan"/></td>
                                </tr>
                                
                                <tr id="trSaveLan" class="even" >
                                    <th>&nbsp;</th>
                                    <td>
                                        <input type="button" id="btnTraceStart" value="<%- btnStart %>"/>
                                        <input type="button" id="btnTraceStop" value="<%- btnStop %>"/>
                                    </td>
                                </tr>
    
                                <tr class="odd">
                                    <th>&nbsp;</th>
                                    <td>
                                        <textarea id="traceTxtResult" cols="80" rows="20"></textarea>
                                        <br>
                                    </td>
                                </tr>
                            </table>
                        </script>
                    <!-- </form> -->        
                </div>
            </div>


            <div class="main_box" id="form4Parent">
                <div id="form4Id">
                    <!-- <form id="form4"> -->
                        <script type="text/template" id="networktoolform4-template">
                            <table class="detail" cellspacing="0">
                                
                                <tr id="trSaveLan" class="even" >
                                    <th>&nbsp;</th>
                                    <td>
                                        <input type="button" id="btnLogStart" value="<%- btnStart %>"/>
                                        <input type="button" id="btnLogStop" value="<%- btnStop %>"/>
                                    </td>
                                </tr>
    
                                    <tr class="odd">
                                    <th><%- th1 %>&nbsp;</th>
                                    <td>
                                        <label id="logLable"></label>
                                        <a id="logLink" href="html/manage/network_tool_log.tar" download><%- downfile %></a>
                                    </td>
                                </tr>
                            </table>
                        </script>
                    <!-- </form> -->
                </div>           
            </div>

            <div class="main_box" id="form5Parent">
                <div id="form5Id">
                    <!-- <form id="form5"> -->
                        <script type="text/template" id="networktoolform5-template">
                            <table class="detail" cellspacing="0">
    
                                <tr>
                                    <th><%- qxdmMessage %></th>
                                    <td>
                                        <input type="checkbox" id="qxdmSwitch" name="qxdmSwitch" /><%- status %>
                                    </td>
                                </tr>
                                
                                <tr class="even" >
                                    <th>&nbsp;</th>
                                    <td>
                                        <input type="button" id="btnSetting" value="<%- btnSetting %>"/>
                                    </td>
                                </tr>
    
                            </table>
                        </script>
                    <!-- </form> -->
                </div>           
            </div>

            
        </div>
    </div>
    <div class="helper_box" style="display:none;">
        <div id="helper"></div>
    </div>
    <span style="clear:both"></span>
</div>